using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_myshop : Member, IRequiresSessionState
{
	public string buyer_credit = "0";
	public string saler_credit = "0";
	protected Shop_Product shopProduct = null;
	protected HyperLink LoginUserName;
	protected Literal LitMemerType;
	protected Literal ShowSalerCredit;
	protected Panel Panelsaler_credit;
	protected Literal ShowBuyerCredit;
	protected Panel Panelbuyer_credit;
	protected Literal UserEp;
	protected Literal Balance;
	protected Literal FreezeMoney;
	protected Literal lastlogintime;
	protected Literal lastloginip;
	protected Literal Buyer_Order;
	protected Literal Buer_Review;
	protected HtmlGenericControl Lbuyer;
	protected Literal Saler_Reme;
	protected Literal Saler_SoldOut;
	protected Literal Saler_OnSale;
	protected Literal Saler_Stock;
	protected Literal Saler_Order;
	protected Literal Saler_Deliver;
	protected Literal Saler_Dule;
	protected Literal Saler_Cash;
	protected HtmlGenericControl Lsaler;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.shopProduct = new Shop_Product();
			this.LoginUserName.Text = base.user.UserName;
			this.lastloginip.Text = base.user.LastLoginIP;
			this.lastlogintime.Text = base.user.LastLoginTime.IsNull(new object[0]);
			base.user.GetUserInfor();
			this.saler_credit = base.user.SaleCrediet;
			this.buyer_credit = base.user.BuyCrediet;
			this.Balance.Text = base.user.Balance.ToString2();
			this.UserEp.Text = base.user.UserEP.IsNull(new object[0]);
			this.JustAndShowMemberType(base.user.UserID);
			this.ShowFreezeMoney();
			this.ShowSalerCredit.Text = "<script type='text/javascript'>displayStar(" + this.shopProduct.BindSaleCrediet(base.user.UserID) + ");</script>";
			this.ShowBuyerCredit.Text = "<script type='text/javascript'>displayStar(" + this.shopProduct.BindBuyCrediet(base.user.UserID) + ");</script>";
			this.ShowBuyerSaler();
		}
	}
	public void ShowFreezeMoney()
	{
		DataTable dataTable = this.conn.GetDataTable("select FreezeMoney from  HL_User where UserID=" + base.user.UserID);
		if (dataTable.Rows[0]["FreezeMoney"].ToDecimal2() == 0m)
		{
			this.FreezeMoney.Text = "";
		}
		else
		{
			string str = dataTable.Rows[0]["FreezeMoney"].IsNull(new object[0]);
			this.FreezeMoney.Text = "冻结资金:￥" + str;
		}
	}
	public void JustAndShowMemberType(int UserID)
	{
		DataSet dataSet = this.conn.GetDataSet("select b.GroupName as GroupName from HL_User as a,HL_Group as b where a.GroupID=b.GroupID and a.UserID=" + UserID);
		if (dataSet.Tables[0].Rows.Count > 0)
		{
			this.LitMemerType.Text = dataSet.Tables[0].Rows[0]["GroupName"].IsNull(new object[0]);
		}
	}
	protected void GetRemindMe(bool ShowBuyer, bool ShowSaler)
	{
		int userID = base.user.UserID;
		string text = DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00";
		if (ShowBuyer)
		{
			string text2 = "0";
			string text3 = "0";
			string text4 = "0";
			string text5 = "0";
			string str = string.Concat(new object[]
			{
				" (userid=",
				userID,
				" and inputTime>'",
				text,
				"'  and hlshop_order.OrderFormID=HLShop_OrderItem.OrderFormID)"
			});
			string str2 = string.Concat(new object[]
			{
				" or (inputTime>'",
				text,
				"0' and userid=",
				userID,
				" and DateDiff(s,UpdateTime,getdate())>=0 and hlshop_order.OrderFormID=HLShop_OrderItem.OrderFormID)"
			});
			string sQLString = "select hlshop_order.OrderFormID,hlshop_order.OrderFormNum,Status,DeliverStatus,PayStatus,BuyerReview,InputTime from hlshop_order,HLShop_OrderItem where " + str + str2;
			bool flag = true;
			if (flag)
			{
				DataTable dataTable = DbHelperSQL.GetDataTable(sQLString);
				if (dataTable != null && dataTable.Rows.Count > 0)
				{
					text4 = dataTable.Rows.Count.ToString();
					DataRow[] array = dataTable.Select(" PayStatus=0");
					if (array != null)
					{
						text5 = array.Length.ToString();
					}
					DataRow[] array2 = dataTable.Select(" Status=0");
					if (array2 != null)
					{
						text2 = array2.Length.ToString();
					}
					DataRow[] array3 = dataTable.Select("DeliverStatus=1");
					if (array3 != null)
					{
						text3 = array3.Length.ToString();
					}
					DataRow[] array4 = dataTable.Select("Status=2 and DeliverStatus=1 and PayStatus=1 and BuyerReview<>1");
					if (array4 != null)
					{
						string text6 = array4.Length.ToString();
					}
				}
			}
			string sql = "Select COUNT(*) From [HLShop_Order] as a,[HLShop_OrderItem] as b Where a.OrderFormID=b.OrderFormID and UserID=" + base.user.UserID;
			int num = this.conn.ExecuteCount(sql);
			string sql2 = "select count(*) from HLMall_Credit where ValuerID=" + base.user.UserID + " and JustValuerCredit=1";
			int num2 = this.conn.ExecuteCount(sql2);
			this.Buyer_Order.Text = string.Format(this.Buyer_Order.Text, new object[]
			{
				text4,
				text5,
				text2,
				text3
			});
			this.Buer_Review.Text = string.Format(this.Buer_Review.Text, (num - num2).ToString());
		}
		if (ShowSaler)
		{
			Shop_PayType shop_PayType = new Shop_PayType();
			string str3 = string.Concat(new object[]
			{
				" (o.SalerID=",
				userID,
				" and o.inputTime>'",
				text,
				"')"
			});
			string str4 = string.Concat(new object[]
			{
				" or (o.inputTime>'",
				text,
				"' and o.SalerID=",
				userID,
				" and DateDiff(s,UpdateTime,getdate())>=0)"
			});
			string text7 = "select i.Quantity,o.OrderFormID,o.Status,o.DeliverStatus,o.PayStatus,o.SalerReview from hlshop_order o inner join hlshop_orderItem i on o.OrderFormID=i.OrderFormID where " + str3 + str4;
			DataTable dataTable2 = this.conn.GetDataTable(text7);
			DataTable offLinePayTypeByUserID = shop_PayType.GetOffLinePayTypeByUserID(userID);
			string arg = "0";
			string sQLString2 = string.Concat(new object[]
			{
				"select count(ProductID) from hlshop_product where SalerID=",
				userID,
				" and EndDate>'",
				DateTime.Now.ToString(),
				"' and EnableSingleSell=1 and EnableSale=1 and Stocks>0"
			});
			string arg2 = "0";
			string arg3 = "0";
			string arg4 = "0";
			string arg5 = "0";
			string arg6 = "0";
			bool flag = true;
			int num3 = 0;
			if (flag)
			{
				object single = DbHelperSQL.GetSingle(sQLString2);
				arg3 = ((single != null) ? Convert.ToString(single) : "0");
				string sQLString3 = string.Concat(new object[]
				{
					"select count(*) from hlshop_bankrollItem where salerid=",
					userID,
					" and DateAndTime>'",
					text,
					"' and Status!=1"
				});
				arg6 = ((int)DbHelperSQL.GetSingle(sQLString3)).ToString();
				DataTable dataTable3 = DbHelperSQL.GetDataTable(text7);
				if (dataTable3 != null && dataTable3.Rows.Count > 0)
				{
					int num4 = 0;
					foreach (DataRow dataRow in dataTable3.Rows)
					{
						if (int.Parse(dataRow["DeliverStatus"].ToString()) == 2)
						{
							num4 += (int)dataRow["Quantity"];
						}
					}
					arg = num4.ToString();
					DataRow[] array5 = dataTable3.Select("Status='0'");
					if (array5 != null && array5.Length > 0)
					{
						arg2 = array5.Length.ToString();
					}
					DataRow[] array6 = dataTable3.Select("Status=2 and (SalerReview Is Null Or SalerReview=0)");
					if (array6 != null && array6.Length > 0)
					{
						string text8 = array6.Length.ToString();
					}
					if (dataTable2.Rows.Count > 0)
					{
						for (int i = 0; i < dataTable2.Rows.Count; i++)
						{
							DataTable dataTable4 = this.conn.GetDataTable("select *, (case when MoneyReceipt>=MoneyTotal then 1 else 0 end) as a from HLShop_Order where OrderFormID=" + int.Parse(dataTable2.Rows[i]["OrderFormID"].ToString()));
							if (dataTable4.Rows[0]["a"].ToString() == "1" && dataTable4.Rows[0]["DeliverStatus"].ToString() == "0" && int.Parse(dataTable4.Rows[0]["PayStatus"].ToString()) >= 1)
							{
								num3++;
							}
							dataTable4.Dispose();
						}
					}
					arg4 = num3.ToString();
					DataRow[] array7 = dataTable3.Select("Status>=1 and DeliverStatus=2");
					if (array7 != null && array7.Length > 0)
					{
						arg5 = array7.Length.ToString();
					}
				}
			}
			this.Saler_SoldOut.Text = string.Format(this.Saler_SoldOut.Text, arg);
			this.Saler_OnSale.Text = string.Format(this.Saler_OnSale.Text, arg3);
			this.Saler_Order.Text = string.Format(this.Saler_Order.Text, arg2);
			this.Saler_Deliver.Text = string.Format(this.Saler_Deliver.Text, arg4);
			this.Saler_Dule.Text = string.Format(this.Saler_Dule.Text, arg5);
			this.Saler_Cash.Text = string.Format(this.Saler_Cash.Text, arg6);
		}
	}
	protected void ShowBuyerSaler()
	{
		string groupPower = base.user.GetGroupPower("GroupPower");
		bool flag = groupPower.Contains("showbuy");
		bool flag2 = groupPower.Contains("showsaler");
		if (!flag2)
		{
			this.Panelbuyer_credit.Visible = (this.Panelsaler_credit.Visible = false);
		}
		this.Lbuyer.Visible = flag;
		this.Lsaler.Visible = flag2;
		this.GetRemindMe(flag, flag2);
	}
}
